<?php
namespace Common\Model;

/**
 * 客栈表
 * @modify zhangzhen 2016-12-23 创建
 */

Class AdminSynModel extends \Common\Model\BaseModel
{
    protected $trueTableName = 'tb_admin_syn';
    
    /**
     * 管理员同步表
	 * @modify zhangzhen 2016-12-23  创建  
     * @param  integer   $masterentityId      锁掌柜集群Id
     * @param  integer   $adminLoginId    管理员id
     * @param  integer   $usercommunityId  锁掌柜管理员与集群Id
	 * @param  integer   $hotelId 客栈Id
     * @return boolean 添加结果
     */
    public function addInfo($masterentityId,$adminLoginId,$usercommunityId,$hotelId) {
        $data = array(
            'masterentity_id' => $masterentityId,
            'adminlogin_id' => $adminLoginId,
            'usercommunity_id' => $usercommunityId,
			'hotelentity_id' => $hotelId
        );
        $id = $this->add($data);
        return $id === false ? false : $id;
    }
	/**
     * 获取已同步的管理员
	 * @modify zhangzhen 2016-12-23  创建  
	 * @param  integer   $hotelId 客栈Id
     * @return array 返回数组
     */
	public function getInfoByHotelId($hotelId) {
        $options['hotelentity_id'] = $hotelId;
        $fields = 'tb_admin_login.name as name ,tb_admin_login.mobile as mobile,adminlogin_id,usercommunity_id';
		return $this->field($fields)
					->join('tb_admin_login ON tb_admin_login.id = tb_admin_syn.adminlogin_id','LEFT')
					->where($options)
					->select();
    }
	/**
     * 删除管理员客栈的同步数据
     * @modify songanwei 2016-12-23
     * @param integer $adminId  管理员ID
     * @param integer $hotelId 客栈ID
     * @return type
     */
    public function deleteInfoByAdminHotel($adminId, $hotelId) {
        $where = array(
            'adminlogin_id' => $adminId,
			'hotelentity_id' => $hotelId
        );
        
        $result = $this->where($where)->delete();
        return $result === false ? false : true;
    }
}
